calculatePercentDp

internal fun calculatePercentDp(baseValue: Float, configuration: Configuration, qualifier: DpQualifier, inverter: Inverter, ignoreMultiWindows: Boolean, applyAspectRatio: Boolean, customSensitivityK: Float?, context: Context? = null): Float

EN Shared pure-math scaling kernel used by toDynamicPercentPx and toDynamicPercentDp.

Algorithm summary:

  1. Applies Inverter rules to swap the effective DpQualifier based on screen orientation.

  2. If ignoreMultiWindows is true, detects split-screen mode via layout flags; if active, returns baseValue unchanged so the UI does not over-scale inside a small window.

  3. For the common path (SMALL_WIDTH + DEFAULT inverter + no custom sensitivity), delegates to DimenCache.calculateRawScaling which reads pre-computed factors from DimenCache.ScreenFactors — a single float multiply, zero extra allocations.

  4. For other qualifiers or a custom sensitivity constant, reads the screen dimension from android.content.res.Configuration and performs the scaling formula inline.

Performance: Simple paths without Aspect Ratio complete in ~2 ns (single multiply). Paths with Aspect Ratio require ~41 ns on Snapdragon 888 (includes ln() fallback). Results are memoized by the DimenCache shared across code and compose packages.

Note: Both code/ and compose/ packages intentionally maintain separate copies of this function because the code/ variant operates on android.content.res.Configuration directly (no Compose runtime), while compose/ reads it from androidx.compose.ui.platform.LocalConfiguration. The math is identical; only the Context acquisition path differs.

PT Núcleo de escalonamento puro compartilhado por toDynamicPercentPx e toDynamicPercentDp.

Resumo do algoritmo:

  1. Aplica as regras de Inverter para trocar o DpQualifier efetivo conforme a orientação.

  2. Se ignoreMultiWindows for true, detecta split-screen via flags de layout; se ativo, retorna baseValue sem escalar.

  3. Para o caminho comum (SMALL_WIDTH + DEFAULT + sem sensibilidade customizada), delega para DimenCache.calculateRawScaling com os fatores pré-calculados.

  4. Para outros qualificadores ou sensibilidade customizada, lê a dimensão da tela da android.content.res.Configuration e executa a fórmula de escalonamento inline.

Nota: Os pacotes code/ e compose/ mantêm cópias separadas intencionalmente. A versão code/ opera sobre android.content.res.Configuration diretamente, enquanto a versão compose/ usa androidx.compose.ui.platform.LocalConfiguration. A matemática é idêntica; apenas a obtenção do contexto difere.

Return

Scaled Dp value as a raw Float.

Parameters

baseValue

Raw Dp value to scale (e.g. 16f for 16 dp).

configuration

Current android.content.res.Configuration from the context.

qualifier

Original screen qualifier before inversion.

inverter

Orientation-swap rule.

ignoreMultiWindows

Whether to suppress scaling in multi-window mode.

applyAspectRatio

Whether to apply the AR multiplier.

customSensitivityK

Custom AR sensitivity constant, or null for the library default.